//
//  OSCTweetDetailWithBottomBarViewModel.m
//  OSChina
//
//  Created by 8b410-2 on 17/1/5.
//  Copyright © 2017年 abb. All rights reserved.
//

#import "OSCTweetDetailWithBottomBarViewModel.h"
#import "OSCTweetDetailViewModel.h"
#import "OSCTweetCommentViewModel.h"
@interface OSCTweetDetailWithBottomBarViewModel ()
/// 动弹详情viewModel
@property (nonatomic, strong, readwrite) OSCTweetDetailViewModel *childViewModel;

@end

@implementation OSCTweetDetailWithBottomBarViewModel

@dynamic childViewModel;

- (void)initialize {
    [super initialize];
     @weakify(self);
    
    self.pubCommentParams = [OSCPubCommentRequestParams new];
    self.pubCommentParams.catalog = OSCCommentCatalogTweets;
    self.pubCommentParams.idField = self.childViewModel.tweetViewModel.idField;
    
    // 点击评论cell处理
    [self.childViewModel.didSelectCommand.executionSignals.switchToLatest subscribeNext:^(OSCTweetCommentViewModel *commentViewModel) {
        @strongify(self);
        // 创建"@xxx "格式的属性字符串
        NSString *authorString = [NSString stringWithFormat:@"@%@ ",commentViewModel.commentAuthor];
        NSMutableAttributedString *authorAttribute = [[NSMutableAttributedString alloc] initWithString:authorString];
        [authorAttribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15.0] range:NSMakeRange(0, authorAttribute.length)];
        // 拼接到 评论框属性字符串
        NSMutableAttributedString *mutableAttribute = [[NSMutableAttributedString alloc] initWithAttributedString:self.commentViewAttribute];
        [mutableAttribute appendAttributedString:[authorAttribute copy]];
        // 同时设置给恢复的草稿字符串
        self.restoreDraftAttribute = [[NSAttributedString alloc] initWithAttributedString:[mutableAttribute copy]];
    }];
}

@end
